package com.edu.study.base.stuQuestionCatalog.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.edu.study.base.stuQuestionCatalog.domain.StuQuestionCatalog;
import com.edu.study.base.stuQuestionCatalog.service.IStuQuestionCatalogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题卷目录Controller
 * 
 * @author jjt
 * @date 2021-05-18
 */
@RestController
@RequestMapping("/study/catalog")
public class StuQuestionCatalogController extends BaseController
{
    @Autowired
    private IStuQuestionCatalogService stuQuestionCatalogService;

    /**
     * 查询题卷目录列表
     */
    @PreAuthorize("@ss.hasPermi('study:catalog:list')")
    @GetMapping("/list")
    public AjaxResult list(StuQuestionCatalog stuQuestionCatalog)
    {
        List<StuQuestionCatalog> list = stuQuestionCatalogService.selectStuQuestionCatalogList(stuQuestionCatalog);
        return AjaxResult.success(list);
    }

    /**
     * 导出题卷目录列表
     */
    @PreAuthorize("@ss.hasPermi('study:catalog:export')")
    @Log(title = "题卷目录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StuQuestionCatalog stuQuestionCatalog)
    {
        List<StuQuestionCatalog> list = stuQuestionCatalogService.selectStuQuestionCatalogList(stuQuestionCatalog);
        ExcelUtil<StuQuestionCatalog> util = new ExcelUtil<StuQuestionCatalog>(StuQuestionCatalog.class);
        return util.exportExcel(list, "catalog");
    }

    /**
     * 获取题卷目录详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:catalog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(stuQuestionCatalogService.selectStuQuestionCatalogById(id));
    }
    /**
     * 获取题卷目录下级信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:catalog:query')")
    @GetMapping(value = "getTreeDataInfo/{id}")
    public AjaxResult getTreeDataInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(stuQuestionCatalogService.selectTreeDataById(id));
    }

    /**
     * 新增题卷目录
     */
    @PreAuthorize("@ss.hasPermi('study:catalog:add')")
    @Log(title = "题卷目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StuQuestionCatalog stuQuestionCatalog)
    {
        stuQuestionCatalog.setCreateId(SecurityUtils.getUserId());
        stuQuestionCatalog.setCreateTime(new Date());
        stuQuestionCatalog.setUpdateTime(new Date());
        stuQuestionCatalog.setUpdateId(SecurityUtils.getUserId());
        return toAjax(stuQuestionCatalogService.insertStuQuestionCatalog(stuQuestionCatalog));
    }

    /**
     * 修改题卷目录
     */
    @PreAuthorize("@ss.hasPermi('study:catalog:edit')")
    @Log(title = "题卷目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StuQuestionCatalog stuQuestionCatalog)
    {
        stuQuestionCatalog.setUpdateTime(new Date());
        stuQuestionCatalog.setUpdateId(SecurityUtils.getUserId());
        if (stuQuestionCatalog.getIfCatalog() != null && "1".equals(stuQuestionCatalog.getIfCatalog())) {
            stuQuestionCatalog.setQuestionTypeId(null);
        }
        return toAjax(stuQuestionCatalogService.updateStuQuestionCatalog(stuQuestionCatalog));
    }

    /**
     * 删除题卷目录
     */
    @PreAuthorize("@ss.hasPermi('study:catalog:remove')")
    @Log(title = "题卷目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stuQuestionCatalogService.deleteStuQuestionCatalogByIds(ids));
    }
}
